home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap04 / SwitchAgent.java < prev    next >
Text File  |  1996-09-20  |  867b  |  32 lines

  1. //
  2. // an agent raises his hand when you click him.
  3. //
  4.  
  5. import vrml.*;
  6. import vrml.node.*;
  7. import vrml.field.*;
  8.  
  9. public class SwitchAgent extends Script{
  10.     SFInt32 setAgentImage;
  11.     boolean normalPosture = true;
  12.     
  13.     public void initialize(){
  14.         // get the reference of the event out 'setAgentImage'.
  15.         setAgentImage = (SFInt32)getEventOut("setAgentImage");
  16.     }
  17.     
  18.     public void processEvent(Event e){
  19.         if(e.getName().equals("touchTime") == true){
  20.             // toggle the state.
  21.             normalPosture = !normalPosture;
  22.             if(true == normalPosture){
  23.                 // make the agent in normal posture.
  24.                 setAgentImage.setValue(0);
  25.             }else{
  26.                 // make the agent in hello posture.
  27.                 setAgentImage.setValue(1);
  28.             }
  29.         }
  30.     }
  31. }
  32.